
#include <stdio.h>

#ifndef __WIN32__
#include <unistd.h>
#include <apr_signal.h>
#define KEYONSIGNAL SIGINT
#endif

#include "aprtools/APRPRNG.h"
#include "iface/APRInterface.h"
#include "iface/SQLiteInterface.h"
#include "iface/SSLInterface.h"

#include "db/ActorsDB.h"
#include "db/KeyDB.h"
#include "db/PendingDB.h"

#include "net/BrokerMessage.h"
#include "net/Broker5Server.h"
#include "net/BlockWriteServer.h"
#include "utils/Prompt.h"

#include "default_hosts.h"
#include "acquire_config.h"

#include "testTCPServer.h"
#include "testHTTPServer.h"
#include "testUDPServer.h"

int allstop;

#ifndef __WIN32__
void signal_setflag(int signo)
{
   printf("Received signal (%d ? %d)\n", signo, KEYONSIGNAL);
   if (signo == KEYONSIGNAL)
      allstop = 1;
}
#endif

int main(int argc, const char *argv[])
{
   int nargc = argc;
   const char *const *nargv = argv;
   APRInterface apr_iface = APRInterface::getInstance(&nargc, &nargv);
   SSLInterface ssl_iface = SSLInterface::getInstance();
   SQLiteInterface sqlite_iface = SQLiteInterface::getInstance();
   allstop = 0;
#ifndef __WIN32__
   apr_sigfunc_t *sighandler = apr_signal(KEYONSIGNAL, &signal_setflag);
#endif

   if (strcmp(argv[1], "--tcp") == 0)
      tests::testTCPServer("0.0.0.0", 10000, apr_iface.getGlobalPool());
   if (strcmp(argv[1], "--http") == 0)
      tests::testHTTPServer("0.0.0.0", 10000, apr_iface.getGlobalPool());
   if (strcmp(argv[1], "--udp") == 0)
      tests::testUDPServer("0.0.0.0", 10000, apr_iface.getGlobalPool());

   APRPRNG::forceDestruction();
   return 0;
}
